package com.sari.common.utils.excel;

import com.google.common.collect.Lists;
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.List;

/**
 * Created by Hizhengfu on 2014/4/24.
 * 导出excel 标题
 */
public class ExcelHeader {
    //标题名
    private String name;

    private List<String> fields = Lists.newArrayList();

    //起始行
    private int firstRow;
    //结束行
    private int lastRow;
    /*起始列 一般情况下不需要写*/
    private int firstCol;
    //结束列
    private int lastCol;

    /*标题所占长度，以便合并计算*/
    private int len;
    //所属列样式
    private String style;
    //标题方向 ,默认为横向标题
    private boolean direction;

    //获取合并表格信息
    public CellRangeAddress getCellRangeAddress() {
        if (lastRow == 0 && lastCol == 0) return null;
        return new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /*标题字段集合*/
    public void setField(String field) {
        fields.add(field);
    }

    public List<String> getFields() {
        return fields;
    }

    public void setFields(List<String> fields) {
        this.fields = fields;
    }

    public int getFirstRow() {
        return firstRow;
    }

    public void setFirstRow(int firstRow) {
        this.firstRow = firstRow;
    }

    public int getLastRow() {
        return lastRow;
    }

    public void setLastRow(int lastRow) {
        this.lastRow = lastRow;
    }

    public int getFirstCol() {
        return firstCol;
    }

    public void setFirstCol(int firstCol) {
        this.firstCol = firstCol;
    }

    public int getLastCol() {
        if (getFirstCol() > 0) lastCol = getFirstCol() + len - 1;
        return lastCol;
    }

    public void setLastCol(int lastCol) {
        this.lastCol = lastCol;
    }

    public int getLen() {
        if (len == 0) len = fields.size() > 0 ? fields.size() : 1;
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    public boolean isDirection() {
        return direction;
    }

    public void setDirection(boolean direction) {
        this.direction = direction;
    }
}
